//
//  QRCodeView.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/8/24.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "QRCodeView.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "BLHeader.h"

@interface QRCodeView ()
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UIImageView *codeImage;

@property (weak, nonatomic) IBOutlet UIView *contentView;

@end

@implementation QRCodeView

+ (instancetype)qrCodeView {
    QRCodeView *codeView = [[[NSBundle mainBundle] loadNibNamed:@"QRCodeView" owner:nil options:nil] lastObject];
    return codeView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
}


- (void)setupUI {
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
}


- (void)setCodeURL:(NSString *)codeURL {
    _codeURL = codeURL;
    [self.codeImage sd_setImageWithURL:[NSURL URLWithString:_codeURL] placeholderImage:nil];
    [self layoutIfNeeded];
}

- (IBAction)closeEvent:(id)sender {
    if ([self.delegate respondsToSelector:@selector(closeView)]) {
        [self.delegate closeView];
    }
}

- (void)show:(UIView *)showWhereView withAmimation:(BOOL)animation {
    [showWhereView addSubview:self];
    self.frame = CGRectMake(KScreenWidth, KScreenHeight, KScreenWidth, KScreenHeight);
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = showWhereView.frame;
    }];
}



@end
